FUNCTION YBC_SWS_GET_HISTORY.
*"----------------------------------------------------------------------
*"*"本地接口：
*"  IMPORTING
*"     VALUE(IV_REQUESTID) TYPE  YBC_SWS_REQUEST-REQUESTID
*"     VALUE(IV_ACTLPROC_ONLY) TYPE  CHAR1 DEFAULT 'X'
*"  EXPORTING
*"     VALUE(ES_MSG) TYPE  BAPIRET2
*"     VALUE(ET_HISTORY) TYPE  YBCT_SWS_HISTORY
*"----------------------------------------------------------------------
  DATA:
    LV_INDEX    TYPE I,
    LS_APPROVER TYPE YBC_SWS_APPROVER,
    LT_APPROVER TYPE STANDARD TABLE OF YBC_SWS_APPROVER,
    LS_HISTORY  LIKE LINE OF ET_HISTORY,
    LS_USER     TYPE YBC_SWS_USER,
    LT_USER     TYPE STANDARD TABLE OF YBC_SWS_USER.

  FIELD-SYMBOLS <FS_FIELD> TYPE ANY TABLE.

  REFRESH ET_HISTORY[].
  CLEAR ES_MSG.

  SELECT *
    FROM YBC_SWS_APPROVER
    INTO TABLE LT_APPROVER
    WHERE REQUESTID = IV_REQUESTID.

  IF SY-SUBRC <> 0.
    ES_MSG-TYPE = 'E'.
    MESSAGE S010(YBC_SWS) INTO ES_MSG-MESSAGE WITH IV_REQUESTID.
    RETURN.
  ENDIF.

  IF IV_ACTLPROC_ONLY IS NOT INITIAL..
    DELETE LT_APPROVER WHERE PROCESSED IS NOT INITIAL AND ACTUALPROCESSED IS INITIAL.
  ENDIF.

  SELECT *
    INTO TABLE LT_USER
    FROM YBC_SWS_USER
    FOR ALL ENTRIES IN LT_APPROVER
   WHERE USERID = LT_APPROVER-APPROVERID.

  SORT LT_USER BY USERID ASCENDING.

  LOOP AT LT_APPROVER INTO LS_APPROVER.
    CLEAR LS_HISTORY.
    MOVE-CORRESPONDING LS_APPROVER TO LS_HISTORY.
    CONCATENATE LS_APPROVER-RDATE LS_APPROVER-RTIME INTO LS_HISTORY-RDATETIME.
    CONCATENATE LS_APPROVER-ADATE LS_APPROVER-ATIME INTO LS_HISTORY-ADATETIME.
    CONCATENATE LS_APPROVER-COMMENTS LS_APPROVER-REMARKS INTO LS_HISTORY-COMMENTS SEPARATED BY SPACE.

    CLEAR LS_USER.
    READ TABLE LT_USER INTO LS_USER WITH KEY USERID = LS_APPROVER-APPROVERID.
    IF SY-SUBRC = 0.
      CONCATENATE LS_USER-NAME1 LS_USER-NAME2 LS_USER-NAME3 INTO
      LS_HISTORY-APPROVER_NAME SEPARATED BY SPACE.
    ENDIF.

    CONDENSE LS_HISTORY-APPROVER_NAME.
    CONDENSE LS_HISTORY-COMMENTS.
    APPEND LS_HISTORY TO ET_HISTORY.
  ENDLOOP.

  SORT ET_HISTORY BY REQUESTID ASCENDING RDATETIME DESCENDING ADATETIME DESCENDING.

ENDFUNCTION.
